package shop.milvus.config;

import io.milvus.client.MilvusClient;
import io.milvus.client.MilvusServiceClient;
import io.milvus.param.ConnectParam;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import shop.milvus.MilvusService;
import shop.milvus.ServiceImpl.MilvusServiceImpl;

@Configuration
@RequiredArgsConstructor
@EnableConfigurationProperties(MilvusProperties.class)
public class MilvusAutoConfiguration {
    private  final MilvusProperties properties;

    @Bean
    @ConditionalOnMissingBean
    public MilvusClient milvusClient(){
        ConnectParam connectParam=ConnectParam.newBuilder()
                .withHost(properties.getHost())
                .withPort(properties.getPort())
                .build();
        return new MilvusServiceClient(connectParam);

    }
    @Bean
    @ConditionalOnMissingBean
    public MilvusService milvusService(MilvusClient milvusClient){
        return new MilvusServiceImpl(milvusClient);
    }
}
